/**
 * 
 */
package tests;

import static org.junit.Assert.*;
import interfaces.Board;
import interfaces.Cell;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import plugins.AliveState;
import plugins.DeadState;
import framework.BoardImpl;

/**
 * @author bcharna
 * 
 */

public class BoardImplTest {
	
	@Test
	public void newBoardTest()
	{
		final int WIDTH = 100;
		final int HEIGHT = 101;
		
		// ensure Cell[][] array lengths are right
		Board b = new BoardImpl(WIDTH, HEIGHT);
		assertEquals(WIDTH, b.getWidth());
		assertEquals(HEIGHT, b.getHeight());

		assertEquals(WIDTH, b.getCells().length);
		for (int x = 0; x < b.getWidth(); x++) // each col has 101 rows
			assertEquals(HEIGHT, b.getCells()[x].length);


		// ensure every cell on board is Dead
		for (int x = 0; x < b.getWidth(); x++)
			for (int y = 0; y < b.getHeight(); y++)
			{
				assertEquals(new DeadState().getClass(), b.getCells()[x][y].getState().getClass());
				assertEquals(new DeadState().getClass(), b.getCell(x, y).getState().getClass());
			}
	}
	
	@Test
	public void stateChangeTest()
	{
		Board b = new BoardImpl(100, 100);
		// ensure every cell on board is Dead
		for (int x = 0; x < b.getWidth(); x++)
			for (int y = 0; y < b.getHeight(); y++)
			{
				assertEquals(new DeadState().getClass(), b.getCells()[x][y].getState().getClass());
				assertEquals(new DeadState().getClass(), b.getCell(x, y).getState().getClass());
				// change to alive state
				Cell c = b.getCell(x, y);
				c.setState(new AliveState());
			}
		//ensure all are alive now.
		for (int x = 0; x < b.getWidth(); x++)
			for (int y = 0; y < b.getHeight(); y++)
			{
				assertEquals(new AliveState().getClass(), b.getCells()[x][y].getState().getClass());
				assertEquals(new AliveState().getClass(), b.getCell(x, y).getState().getClass());
			}
	}
	

	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
	}

	/**
	 * @throws java.lang.Exception
	 */
	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void test() {
		//fail("Not yet implemented");
	}

}
